ProductsLogo
LogoStudy Documents
LogoAI Grader
LogoAI Answer
LogoAI Code Checker
LogoPlagiarism Checker
LogoAI Paraphraser
LogoAI Quiz
LogoAI Detector
PricingBlogAbout Us
logo

Java Programming Assignments with Solutions

Verified

Added on  2023/06/04

|9
|904
|164
AI Summary
This page contains solved assignments for Java programming with solutions. The assignments cover topics like time conversion, Roman numeral conversion, and more. The code is written in Java programming language and is suitable for beginners and intermediate learners. The assignments include step-by-step solutions and are perfect for improving your programming skills.

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Java programming
= |

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Java programming
Question 1
package a2q1;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class A2Q1 {
public static void main(String[] args) {
Scanner n= new Scanner(System.in);
System.out.print("Enter the time format:");
int a=n.nextInt();
if(a==24){
System.out.print("Enter time:");
Scanner nu= new Scanner(System.in);
String inputi=nu.nextLine();
A2Q1 t= new A2Q1();
t.conv24(inputi);
}else
if(a==12){
Document Page
Java programming
System.out.print("Enter time:");
Scanner nu= new Scanner(System.in);
String inputi=nu.nextLine();
A2Q1 t= new A2Q1();
t.conv12(inputi);
}else{
System.out.print("Wrong entry");
}
}
public void conv12( String inputi){
DateFormat ft= new SimpleDateFormat("HH:mm");
DateFormat outputformat = new SimpleDateFormat("hh:mm aa");
Date da = null;
String output=null;
try{
da= ft.parse(inputi);
output = outputformat.format(da);
System.out.println(inputi+" to 12hrs clock system is" +output);
}catch(ParseException pe){
pe.printStackTrace();
}
Document Page
Java programming
}
public void conv24(String inputi){
DateFormat ft= new SimpleDateFormat("hh:mm aa");
DateFormat outputformat = new SimpleDateFormat("HH:mm");
Date da = null;
String output=null;
try{
da= ft.parse(inputi);
output = outputformat.format(da);
System.out.println(output);
}catch(ParseException pe){
pe.printStackTrace();
}
}
}

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Java programming
Question 2
package a2q2;
import java.util.Scanner;
public class A2Q2 {
static String romanNumeral;
static int decimalNum;
public static void main(String[] args) {
A2Q2 rmtoD = new A2Q2();
rmtoD .convertToDecimal();
rmtoD .printRoman(romanNumeral);
}
public void convertToDecimal () {
Scanner scan = new Scanner(System.in);
System.out.print("Enter a Roman number: ");
romanNumeral = scan.nextLine();
romanNumeral = romanNumeral.toUpperCase();
int l= romanNumeral.length();
int num=0;
int previousnum = 0;
for (int i=l-1;i>=0;i--)
{
char x = romanNumeral.charAt(i);
x = Character.toUpperCase(x);
Document Page
Java programming
switch(x)
{
case 'I':
previousnum = num;
num = 1;
break;
case 'V':
previousnum = num;
num = 5;
break;
case 'X':
previousnum = num;
num = 10;
break;
case 'L':
previousnum = num;
num = 50;
break;
case 'C':
previousnum = num;
num = 100;
break;
case 'D':
previousnum = num;
num = 500;
break;
case 'M':
previousnum = num;
num = 1000;
Document Page
Java programming
break;
}
if (num<previousnum)
{decimalNum= decimalNum-num;}
else
decimalNum= decimalNum+num;
}
}
public static void printRoman (String romanNumeral){
System.out.println ("The equivalent of the Roman numeral "+romanNumeral+" is
"+decimalNum);
}
public static void printDecimal (int decimalNum){
System.out.println ("Decimal Number stored is: " + decimalNum);
}
}

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Java programming
Question 3
package a2q3;
import java.util.Scanner;
public class A2Q3 {
public static void main(String[] args) {
int i;
System.out.println("Enter n:");
Scanner h = new Scanner(System.in);
int hi=h.nextInt();
System.out.println("Enter rock distsnce");
int []git=new int[hi];
for(i=0;i<hi;i++){
Scanner j = new Scanner(System.in);
git[i]=j.nextInt();
}
System.out.println("Enter m");
Scanner p = new Scanner(System.in);
int po=p.nextInt();
int []jj=new int[po];
String [] name=new String [po];
for(int y=0;y< po;y++){
Document Page
Java programming
Scanner j = new Scanner(System.in);
System.out.println("Enter name");
name[y]=j.nextLine();
System.out.println("Enter step");
jj[y]=p.nextInt();
}
int u;
for(u=0;u< hi;u++){
for(int t=0;t<po;t++){
if(jj[t]> git[u]){
System.out.print(name[t]+":"+jj[t] +"\n2");
}
}
}
System.out.print("The above crossed the river \n");
}
}
1 out of 9
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]