0% found this document useful (0 votes)
52 views

Import Java

This document contains code snippets in Java that demonstrate basic input/output operations like reading input from the console, performing arithmetic calculations on large numbers, and printing output to the console. It includes examples of using classes like Scanner to take input, while loops to repeat operations, and methods to calculate sums and remainders. The snippets handle different data types and operations like strings, integers, and character manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Import Java

This document contains code snippets in Java that demonstrate basic input/output operations like reading input from the console, performing arithmetic calculations on large numbers, and printing output to the console. It includes examples of using classes like Scanner to take input, while loops to repeat operations, and methods to calculate sums and remainders. The snippets handle different data types and operations like strings, integers, and character manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

*;
import java.io.*;
import java.math.*;

public class Main {


public static BigInteger caculate(BigInteger num1, BigInteger num2,
char c){
switch(c) {
case '+':
return num1.add(num2);
case '-':
return num1.subtract(num2);
case '*':
return num1.multiply(num2);
default:
return BigInteger.ZERO;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while(n-- > 0) {
String [] a = sc.nextLine().split(" ");
BigInteger num1 = new BigInteger(a[0]);
BigInteger num2 = new BigInteger(a[2]);
char c = a[1].charAt(0);
BigInteger res = caculate(num1, num2 , c);
System.out.println(res);
}
sc.close();
}

}
TEST BASIC02
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int test=sc.nextInt();
sc.nextLine();
while (test!=0) {
String s=sc.nextLine();
System.out.println(s);
test--;
}
}
}
BASIC 003
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int test=sc.nextInt();
sc.nextLine();
while (test!=0) {
String s=sc.nextLine();
System.out.println("Hi "+s);
test--;
}
}
}
BASIC 005\
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t!=0){
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d=sc.nextInt();
int e=sc.nextInt();
System.out.println((long)a+b+c+d+e);
t--;
}

}
}
BASIC 001
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int test=sc.nextInt();
sc.nextLine();
while (test!=0) {

String s=sc.nextLine();
System.out.println(s);
test--;
}
}
}

ELAB 2312
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s;
while(sc.hasNextLine()){
s = sc.nextLine();
int count = 0;
for(int i = 0; i < s.length(); i++){
if(s.charAt(i)>='0' && s.charAt(i)<='9'){
count++;
}
}
System.out.println(count);
}
}
}

You might also like