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

 java concept input output class

Go down 
AuthorMessage
Admin
Admin
avatar

Posts : 120
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 http://yotamarker.forumotion.com
 
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?
» verifyTrue (FALSE) causes AssertionError: null

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