battle programmers alliance

battle programminga forum for elite programmerswith extreme will powerto sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Search
 
 

Display results as :
 
Rechercher Advanced Search
Latest topics
» android mobile app dev APK
Thu May 17, 2018 6:22 am by Moti Barski

» links/suggestions to become a programmer
Mon May 07, 2018 11:01 pm by Moti Barski

» java eclipse oxygen grimoire
Thu May 03, 2018 8:24 pm by Moti Barski

» forum logo by tf monkey
Wed May 02, 2018 10:17 pm by Moti Barski

» java and MySQL
Mon Apr 30, 2018 3:02 pm by Admin

» mini A.I puzzles
Mon Apr 23, 2018 11:38 am by Moti Barski

» java convert string to unicode
Sun Mar 25, 2018 8:40 pm by Admin

» problem java dynamic web
Sat Mar 24, 2018 6:10 am by Admin

» auto programming dev
Wed Mar 14, 2018 8:42 pm by Admin

May 2018
SunMonTueWedThuFriSat
  12345
6789101112
13141516171819
20212223242526
2728293031  
CalendarCalendar
Social bookmarking
Social bookmarking digg  Social bookmarking delicious  Social bookmarking reddit  Social bookmarking stumbleupon  Social bookmarking slashdot  Social bookmarking yahoo  Social bookmarking google  Social bookmarking blogmarks  Social bookmarking live      

Bookmark and share the address of battle programmers alliance on your social bookmarking website
Share | 
 

 java concept input output class

Go down 
AuthorMessage
Admin
Admin
avatar

Posts : 108
Join date : 2011-08-01

PostSubject: java concept input output class   Tue Feb 20, 2018 7:21 pm

class :
Code:
import java.util.List;
import java.awt.Event;
import java.util.ArrayList;
import java.util.Scanner;

public class InOut {
   private static List<Integer> arrList;
   private static List<String> arrList2;
   private static Integer lim;
   public static void stringEater() {
      arrList2 = new ArrayList<>();
      System.out.println("enter a string or finish");
      Scanner scanny = new Scanner(System.in);
      String in1 = scanny.next();
      while(!(in1.equals("finish"))) {arrList2.add(in1);System.out.println("enter a string or finish");
      in1 = scanny.next();}
   }
   public static void listcontains() {
      System.out.println("enter a string to search");
      Scanner scanny = new Scanner(System.in);
      String in1 = scanny.next();
      String result = arrList2.contains(in1)?"yes":"no"; // short conditional ? jutsu
      System.out.println(result);
      }
   public static void evenUnEvens() {
      // evens :
      System.out.println("Even nums:");
      for (Integer num : arrList) {
         if(num%2==0) {System.out.print(" " + num);}
      }
      System.out.println();
      System.out.println("unEven nums:");
      for (Integer num : arrList) {
         if(num%2!=0) {System.out.print(" " + num);}
      }
      }
   public static void limInput(int amount) {
      arrList = new ArrayList<>();
      lim = amount;
      System.out.println("get ready to enter " + amount + "numbers");
      Scanner scanny = new Scanner(System.in);
      for (int i = 0; i < amount; i++) {
         System.out.println("enter number " + (amount - i) +" numbers to go");
         arrList.add(scanny.nextInt());
      }
   }
   public static int sum() {
      int result=0;
      for (Integer element : arrList) {
         result += element;
      }
      return result;
   }
   public static double avg() {
      int result=0;
      for (Integer element : arrList) {
         result += element;
      }
      return (double)result / (double)lim;
   }
   public static double choser() {
      int result=0;
      Scanner scanny = new Scanner(System.in);
      System.out.println("choose sum or avg");
      
      switch (scanny.next()) {
      case "sum":
         return sum();
      case "avg":
         return avg();
      default:
         break;
      }
      return result;
   }
}
main :
Code:

public class Main {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      InOut.limInput(10);
      System.out.println(InOut.choser());
      InOut.stringEater();
      InOut.listcontains();
      InOut.limInput(13);
      InOut.evenUnEvens();
   }

}

_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
 
java concept input output class
Back to top 
Page 1 of 1
 Similar topics
-
» Cannot locate the class Select in web driver
» [Help] Java input Username field as a timestamp
» Getting the error msg 'Error: Could not find or load main class java-jar' while executing the selenium code in eclipse
» How to pass the multiple input data with or condition to search them?
» Class 4 Softswitch For Rent

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: chit chat-
Jump to: