Program To Accept 10 Name In String And Sorting In Bubble Sort Alphabetically

Jun 10, 2014

import java.io.*;
Class bubble
{
public static void main()throws IOException
{
BuffetedReader br=new BufferedReader (new InputStreamReader (System.in));
int j, k, temp;
String st[]=new string [10];

[Code] .....

View Replies


ADVERTISEMENT

Sort String List Alphabetically With CompareTo Method / If Else Statements - Logic Errors

Oct 6, 2014

I'm having trouble with sorting Strings- 3 strings inputted by user, and I would like to output them in alphabetical order. I've used the str.compareToIgnoreCase method, and then I've tried to loop them through a series of if/ else statements. Everything I've been able to find online (including the forums here) has suggested to use the Comparator class, or to put the strings into an array, and sort list- I really would like to stick with just the String class, and its methods .

The program itself works and compiles, but I am getting logic errors that I have been unable to solve. I'm using IntelliJ Idea, and I've ran it through the built in debugger, about 100+ times (not exaggerating, lol) just to see what it's doing in particular scenarios. For instance, I can get c, a, b, to print out as a,b,c correctly, but a,b,c, will print out as b,a,c.

For me this is kind of like a Sudoku puzzle, or a Rubik's cube! Each time I fix one scenario, it breaks another one, so I don't know if there's a(logic) solution to fix all possible scenarios (abc, acb, bac etc... to all print abc) or if possibly I just need more if statements. I've only pasted in the area where I'm having problems (the if statements). I'm a big fan of the "Next Line" syntax.

(Note: please assume the non relevant content- import Scanner class, main method, etc... I didn't want to paste the entire program.)

System.out.println("Enter the first statement: ");
//input.nextLine();
string1 = input.nextLine();
System.out.println("Enter the second statement: ");
string2 = input.nextLine();
System.out.println("Enter the third statement: ");
string3 = input.nextLine();

[Code] ....

View Replies View Related

Program Can Accept Multiple Filter And Sort Commands At One Time

Mar 9, 2014

What I'm supposed to be doing is making it so the program can accept multiple filter and sort commands at one time, and each should be separated by a whitespace.I was thinking about parsing the input again, using whitespace as the delimiter, then normally progressing with each token, as though there was only one command.

However, coding this the way I'm doing it will firstly probably take hours, and secondly, it's likely not even right. I don't have any real way to determine which token contains which data from the Song objects.These are the specific requirements for this portion:A sort/filter command consists of one or more of the following options:

-year:<year(s)>

-rank:<rank(s)>

-artist:<artist>

-title:<title>

-sortBy:<field>

Any number of these options may be given, and they may be given in any order. If multiple options are specified, they will be separated by whitespace.

GazillionSongs Class (the main)
Java Code:
import java.util.*;
import java.io.*;

[code]....

View Replies View Related

Sorting A Map Alphabetically

Nov 30, 2014

I'm trying to create a method that takes a map and sorts it alphabetically. I think I have the logic correct but I'm getting errors when I run it:

private static void sortMapAlphabetically(
Map<String, String> termsAndDefinitions) {
Map<String, String> tempMap = new Map2<String, String>();

[Code].....

View Replies View Related

Creating Flowchart For Bubble Sort

Apr 27, 2015

I have to make a flowchart that shows a bubble sort. Here is the exact directions: provide a flowchart for a bubble sort, and write the pseudo-code that corresponds to the flowchart. You can assume the existence of a swapElement method (ie. use the predefined process symbol).one that does one pass through the array and returns a boolean if items were swapped (I'll call this the one pass method) another method that repeatedly calls the one pass method until that method returns false.This means that your flowchart will have two separate pieces for the one pass method and for the overall flow of the program (this one would use the predefined process symbol for the one pass method).

I have looked up what a bubble sort. It says it is another type of sort that involves repeatedly stepping through the array comparing adjacent items and swapping them if they are in the wrong order.The sort steps through the list multiple times until no swaps are needed, at which point the list is sorted.

View Replies View Related

Find Out Logic Behind Bubble Sort

Mar 4, 2014

I am trying to find out the logic behind the Bubble sort,

for(a=1; a < size; a++)
for(b=size-1; b >=a ; b--){
if(nums[b-1] > nums[b]){
t=nums[b-1];
nums[b-1] = nums[b];

[code]....

View Replies View Related

Sorting A Text File Alphabetically

Oct 13, 2014

So we have to create a code that reads in a file that has a huge list of words. Our code has to convert every word to all lower cases and then re-sort alphabetically. I was able to turn everything to lower case, but for the re-sorting I keep getting a null pointer exception on the line of the if statement.

import java.io.*;
public class readDict {
public static void main(String args[]) {
try {
System.out.println("Opening the file...");

[Code] ....

View Replies View Related

Sorting Data Alphabetically By Second Name In A File?

Apr 11, 2013

I have a problem sorting this file alphabetically by second name. Basically, my method sorts each column alphabetically but i would like to sort the file according to the second name.

File:
Moe     Carl
Saul     Sergio
Rocky     Louis
Ike     Ziken     

This is how my method sorts the file:

Ike          Carl
Moe          Louis
Rocky          Sergio
Saul          ziken
     
Instead
Moe     Carl
Rocky      Louis
Saul     Sergio
Ike     Ziken

Code :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
class thedata implements Comparable
     {               
          private String firstname;
          private String secondname;

[Code] .....

View Replies View Related

Bubble Sort - Array Out Of Bounds Exception

Jan 10, 2015

I am having trouble with an array out of bounds exception. I understand what the error means (that I am trying to access part of array that does not exist). But I do not see the error in my code.

Java Code:

public class bubbleSort
{
public static void main(String []args)
{
int i;
int array [] = {12,9,4,99,120,1,3,10};

[code]....

View Replies View Related

Linking Elements Of Two Arraylists Together For A Bubble Sort?

Jun 13, 2014

I have been doing a program that allows the user to input students names and numerical grade values. I have already completed 3/4 of the program but am stuck on the bubblesort method as this is what it requires:

The program must have an indefinite loop, which prompts the user to select a sorting criterion or to end the program, and must also use bubble sort. Note: The user may either select name or grade as the sorting criteria. The program must use bubble sort to sort that data according to the specific criteria and then use another loop to display the data. This process must continue until the user ends the program.

My problem is, while i can easily do the bubblesort, where to look on how to link elements of the two arraylists I'm using (one for grades, one for names) so that when the user decides what sort they want, the individual's name and grade stays together.

View Replies View Related

Program Will Only Accept Input From 1 String?

Jan 14, 2015

I am trying to create a fortune teller and everything is running fine except the program does not prompt you to answer the questions

Do you like donuts?
and
What did you have for breakfast?

Here is the code this is in Bluej :

import java.util.Scanner;
public class FortuneTeller {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Fortune Teller");

[Code] .....

View Replies View Related

Sort User Input 3 Words Alphabetically And Output Middle Word

Feb 8, 2014

I have a project requiring me to build a program having a user input 3 words, sort them alphabetically and output the middle word. I have done some searching and seem to only come back with results for sorting 2 words. I so far have code to get the user input but I am completely lost as to how to sort them alphabetically.

import java.util.Scanner; //The Scanner is in the java.util package.
public class MiddleString {
public static void main(String [] args){
Scanner input = new Scanner(System.in); //Create a Scanner object.
String str1, str2, str3;
System.out.println("Please enter three word words : "); //Prompt user to enter the three words

[Code]...

we havnt done arrays yet and I THINK i have to do compareTo.....how to use it?

View Replies View Related

Program To Accept String Float And Integer As Command Line Arguments

Feb 8, 2015

Write a java program to accept a string, float and an integer as command line arguments. String value should be displayed. Also the program should display the maximum value of two numbers. Use Integer.parseInt() and Float.parseFloat()

View Replies View Related

Selection Sort Method - Sorting Array And Return Result Of Each Step

Nov 20, 2014

This time I am having difficulties with selection sort method, but not with the method itself (I think). So I need to sort an array and return the result of each step.

This is the main code:

public class Functionality {
public static int[][] selctionsort(int[] a) {
for (int i=0; i<a.length; i++) {
int least = i;
for (int j=i+1; j<a.length; j++)

[Code] ....

And this is the Test folder:

import static org.junit.Assert.assertArrayEquals;
 public class PublicTests {
public static void main(String[] args) {
int[] a = new int[] { 35, 7, 63, 42, 24, 21 };
int[][] b = new int[][] { new int[] { 7, 35, 63, 42, 24, 21 },

[Code] ....

Now I am not sure what should I write in return since the 2nd (test) project has int[][] and in my main project I am working with int [].

View Replies View Related

Encode URL String - It Will Accept Only 1 String Argument

Mar 30, 2015

I've a problem in encoding a URL string.

I know to encode a string we use,

URLEncoder.encode(stringname,"UTF-8");

But when I use this I'm getting an error telling that the encode method will accept only 1 String argument.

View Replies View Related

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

View Replies View Related

Test Driver Does Not Accept String Parameter

Jan 6, 2015

I wrote a couple classes and am trying a test driver but it is having an error I do not know how to solve.

Student Class:

public class Student{
private Course[] courseList;
private static int numCourses;
private final int maxCourses;
public Student(int max){
maxCourses = max;

[Code] .....

Error:
javac tester.java
tester.java:6: error: cannot find symbol
one = new Course(name);
^
symbol: variable name
location: class tester
1 error

Same issue, just only one error as there is only one line. It seems like it does not accept my parameters as it cannot find symbol.

I forgot to put the "" in the brackets, it's been a month since I have looked at any java and made this simple mistake.

View Replies View Related

Accept A String And Display All Palindrome Words

Jan 23, 2015

The program is to accept a string and display all the palindrome words(the words that are same even if they are reversed-------->mom,madam,malayalam etc.)in the string.

I need to solve this program urgently.

There are no syntax errors but after typing in the sentence,no output is displayed. This is my program....

import java.util.*;
class palindrome_test
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a sentence");
String usersInput=in.nextLine();

[Code] .....

View Replies View Related

Program Won't Accept Command Lines?

Oct 24, 2014

A friend and I are working on a project in which we must test "super anagrams" (anagrams in which all characters in the first string are found in the second). We have a driver and definitions class pasted below:

Definition
class SuperAnagram{
String left = new String("");
String right = new String("");

[code]....

In the driver class, we get "cannot find symbol" errors at the beginning of cleanStrings and isSuper, both inside and outside of the if statement.

View Replies View Related

Program That Will Accept Values And Transform Scores To Grade

Aug 26, 2014

I was trying to write a program that will accept values and transform the scores to grade. Like 70 and above will be given A from 60 to 69 is B, from 50 to 59 is C, from 40 to 49 is D and below 40 is F. I have defined the variables, for the textfield, am confused on how make this hapen on just a click of the comand botton.

View Replies View Related

Program That Accept Input Of Positive Integer And Sum All Digits

Jan 28, 2015

I am attempting to write a program that accepts input of a positive integer, reports each digit and then the sum of all digits. This is what I have so far:

*/
 package numbersum;
import java.util.*; 
public class Week4NumberSum {
static Scanner console = new Scanner(System.in); 
/**
* @param args the command line arguments

[Code]...

It works if I enter 1234567891 (10 digits)
Enter a positive integer: 1234567891
digit: 1
digit: 2
digit: 3
digit: 4
digit: 5
digit: 6
digit: 7
digit: 8
digit: 9
digit: 1

The sum of the digits is 46

But if I enter 11 digits, it fails:

Enter a positive integer: 123456789123 (12)
Exception in thread "main" java.util.InputMismatchException: For input string: "123456789123"
at java.util.Scanner.nextInt(Scanner.java:2123)
at java.util.Scanner.nextInt(Scanner.java:2076)
at week4numbersum.Week4NumberSum.main(Week4NumberSum. java:26)

java - Scanner error with nextInt() - Stack Overflow gives me some infor for InputMismatchException - which I find described as In order to deal with this exception you must verify that the input data of your application meet its specification. When this error is thrown, the format of the input data is incorrect and thus, you must fix it, in order for your application to proceed its execution.

I don't understand why the 10 digit integer is OK but the 11 or > digit integer is a mismatch.

View Replies View Related

Sort String Method

Aug 7, 2014

I am getting incombatable types, I do not know why I am getting them..why I am getting the error?

The Error I am getting:
stringSort.java:26: error: incompatible types
if(myArray[j].compareToIgnoreCase(myArray[i].toString())){
^
required: boolean
found: int
*/

[code]....

View Replies View Related

Sorting Array Of Objects Based On One Of Class String Variables

Apr 8, 2014

I have a school assignment that involves me sorting an array of objects based on one of the class String variables. I am using as the title says a simple selection sort method. The problem I'm having is that when I run the program in debug mode, it never seems to enter the if statement in the inner loop. I would like to say I've tried a number of things to figure it out, but honestly I'm just stumped as to why it's not working.

Here is the code:

public static void sortTransactions(Transaction[] oTransaction){// This is the sorting method, obviously it's not done so it currently just prints to screen.
System.out.println("Successful call to sortTransaction()");
String min = "";
int curInd = 0;
Transaction[] temp = new Transaction[1];

[Code] ....

The output when I check to see if the array is sorted verifies that the array never does get sorted.

View Replies View Related

Creating Merge Sort For String Arrays

Mar 31, 2014

I'm having a problem printing out the descending order of my array. The array order goes like (Title,Studio,Year). I try to create to ints with the compareTo method but when the program is run the I get array out of bounds. Could the answer possibly be that in order not not have the out of bounds error, to create a for loop inside of the while?

public class Movie2
{
// instance variables
private int year;
private String Title;
private String Studio;

[code]...

View Replies View Related

Program That Accept Words And Their Meanings Or Display List Of Words In Lexicographical Order

Apr 15, 2015

Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.

Use the JOptionPane class to enter the information.

Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:

- A WordMeaning class that hold the name of a word and its meaning.
- A WordMeaningNode class that creates the node of information and its link field.
- A WordList class that creates and maintain a linked list of words and their meanings.
- A Dictionary class that test your classes.

For the output, the program should produce two scrollable lists:

- The current list of words and their meanings.
- The list of the deleted words. You need not list the meanings, just the words.

So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.

WordMeaning Class:

public class WordMeaning {
String name;
String definition;
WordMeaning(String t, String d) {
name = t;
definition = d;

[Code] .....

View Replies View Related

Program Is To Accept Number And Display New Number After Removing All Zeros

Dec 29, 2014

ex
Sample input:2340980
Sample Output:23498

this is the program i have tried but is dosent work

import java.util.*;
class zero
{
public static void main(String args[])
{

[Code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved